package com.example.administrator.dagger2demo.ui.index;

import android.util.Log;

import com.example.administrator.dagger2demo.adapter.inter.Indo;
import com.example.administrator.dagger2demo.http.RestApi;

import java.util.ArrayList;

import javax.inject.Inject;

import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/4/13.
 */
public class IndexPresenter implements IndexContract.IndexActionsListener {

    private final RestApi _restApi;
    private final IndexContract.View mview;

    @Inject
    public IndexPresenter(RestApi restApi, IndexContract.View view) {
        Log.i("TAG", "进入了...IndexPresenter");
        this._restApi = restApi;
        Log.i("TAG", _restApi == null ? "进入了...is null" : "进入了...not null");
        this.mview = view;
        Log.i("TAG", mview == null ? "进入了...is null" : "进入了...not null");
    }

    @Override
    public void requestIndex(Observer<ArrayList<Indo>> observer) {
        Observable<ArrayList<Indo>> observable = _restApi.requestIndexs();
        observable
                .subscribeOn(Schedulers.io())//订阅调度在io流线程
                .observeOn(AndroidSchedulers.mainThread())//观察调度主线程
                .subscribe(observer);

    }

    @Override
    public void loginSuccess(String message) {
    }

    @Override
    public void loginError(String message) {

    }

}
